package 力扣;

/**
 * @author yyq
 * @create 2022-04-08 14:15
 */
public class leetcode222 {
    public int countNodes(TreeNode root) {
        if(root==null) return 0;
        int[] count =new int[1];
        count[0]=0;
        preOrderCount(count,root);
        return count[0];
    }

    private void preOrderCount(int[] count, TreeNode root) {
        count[0]++;
        if(root.left!=null){
            preOrderCount(count,root.left);
        }
        if(root.right!=null){
            preOrderCount(count,root.right);
        }
    }
}
